from util import *
from const import const
import importlib
import sys
import os
import time
sys.path.append(os.getcwd().replace('\\', '/')+'/src')

def main():
    m = ['' for _ in range(100)]
    # 引用带数字的py模组
    for fileName in os.listdir('./src'):
        num = ''
        try:
            num = int(fileName[0:2])
            m[num] = importlib.import_module(
                fileName.replace('.py', ''))
            continue
        except ValueError:
            pass
        try:
            num = int(fileName[0])
            m[num] = importlib.import_module(
                fileName.replace('.py', ''))
            continue
        except ValueError:
            pass

    numList = [12,3,14,18,2]
    for num in numList:
        while True:
            try:
                m[num].main()
                break
            except Exception as err:
                if str(err) != 'restart':
                    util.logOut(__file__,'====================')
                    util.logOut(__file__,'Exception err: {}'.format(err))
                    util.logOut(__file__,format(traceback.format_exc()))
                    util.logOut(__file__,'====================')
                const.restartProcess()
                continue
        time.sleep(2.000)

    # 领取任务奖励
    const.backMainProcess()
    x, y = const.picLoop(const.publicPath() + 'bmp/mission.jpg')
    util.click(x, y)
    const.picLoop(const.publicPath() + 'bmp/is_mission.jpg')
    time.sleep(2.000)
    x, y = util.findPic(const.publicPath() + 'bmp/get_all_reward.jpg')
    if x != -1 and y != -1:
        util.click(x, y)
        x, y = const.picLoop(const.publicPath() + 'bmp/get_items.bmp')
        util.click(x, y)
    const.backMainProcess()
